# coding=utf-8
# author:xc
# datetime:2018/10/23 14:00
from dbConnection.MysqlConn import Mysql
from . import api
from app import upload_files
from app import util


@api.route('/api/check/news_version', methods=['POST', 'GET'])
def user_version():
    sql = 'select version_num,url,version_code from version where id = (select max(id) from version where status = 1)'
    mysql = Mysql()
    res = mysql.getOne(sql, None)
    mysql.dispose()
    status = 'error'
    versionName = '1.0'
    versionCode = 1
    control = 0
    url = ''
    if res is not None:
        versionName = res['version_num']
        versionCode = res['version_code']
        url = upload_files.baseUrl + res['url']
        status = 'success'

    data = {
        'versionName': versionName,
        'versionCode': versionCode,
        'url': url,
        'status': status,
        'control': control
    }
    return util.to_json(data)
